<?php
include('../bootstrap.php');

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Game\Entity\Character;
use Game\Generator\Generator;
use Game\Action;
use Game\Factory\ActionFactory;
use Game\Exception\IsDeadException;

$app_conf = App\Globals::init()->getConfig()->get('app');
$content = sprintf('<h1>%s &mdash; version %s</h1>', $app_conf['name'], $app_conf['version']);

$em = App\Globals::init()->getEntityManager();

$player = $em->getRepository('Game\Entity\Person')->find(2);
$player instanceof Game\Entity\Character;

$env = $player->getEnvironment();

$request = Request::createFromGlobals();
$command = $request->get('command');

if( $env )
{
    $chars = $env->getOtherCharacters($player);
}


$bot = $em->getRepository('Game\Entity\Character')->find(1);
$bot instanceof Game\Entity\Character;

$items = $player->getItems();
$content.= sprintf('<p>Player %s has items: %s</p>', $player, implode(', ', $items->toArray()));

$player->addAction(ActionFactory::getInstance()->createPunch());
$bot->addAction(ActionFactory::getInstance()->createPunch());

try
{
    while( $player->isAlive() and $bot->isAlive() )
    {
        $content.= sprintf('<p>%s</p>', $player->getAction('punch')->execute($bot));
        $bot->checkForDeath();
        $content.= sprintf('<p>%s</p>', $bot->getAction('punch')->execute($player));
        $player->checkForDeath();
    }
}
catch (Game\Exception\IsDeadException $e)
{
    $content.= sprintf('<p>%s</p>', $e->getMessage());
}

$response = new Response($content);
$response->setCharset('utf-8');
$response->send();

foreach($items as $item)
{
    echo $item->getType();
}